#include "Includes.h"

#include "dt_common2.h"


const char* DVariant::ToString()
{
	static char text[128];

	switch ( m_Type )
	{
	case DPT_Int : 
		sprintf_s( text, sizeof(text), "%i", m_Int );
		break;
	case DPT_Float :
		sprintf_s( text, sizeof(text), "%.3f", m_Float );
		break;
	case DPT_Vector :
		sprintf_s( text, sizeof(text), "(%.3f,%.3f,%.3f)", 
			m_Vector[0], m_Vector[1], m_Vector[2] );
		break;
#if 0 // We can't ship this since it changes the size of DTVariant to be 20 bytes instead of 16 and that breaks MODs!!!
	case DPT_Quaternion :
		sprintf_s( text, sizeof(text), "(%.3f,%.3f,%.3f %.3f)", 
			m_Vector[0], m_Vector[1], m_Vector[2], m_Vector[3] );
		break;
#endif
	case DPT_String : 
		if ( m_pString ) 
			return m_pString;
		else
			return "NULL";
		break;
	case DPT_Array :
		sprintf_s( text, sizeof(text), "Array" ); 
		break;
	case DPT_DataTable :
		sprintf_s( text, sizeof(text), "DataTable" ); 
		break;
	default :
		sprintf_s( text, sizeof(text), "DVariant type %i unknown", m_Type ); 
		break;
	}

	return text;
}

// This can be used to set the # of bits used to transmit a number between 0 and nMaxElements-1.
int NumBitsForCount( int nMaxElements )
{
	int nBits = 0;
	while ( nMaxElements > 0 )
	{
		++nBits;
		nMaxElements >>= 1;
	}
	return nBits;
}